cmake_minimum_required(VERSION 3.20)

project(CppDemo LANGUAGES CXX)

# if (CMAKE_SIZEOF_VOID_P EQUAL 4)
#     set(COMPILEBIT "32")
# else ()
#     set(COMPILEBIT "64")
# endif ()

# if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
#     message("Setting build type to 'RelWithDebInfo' as none was specified.")
#     set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
#     # Set the possible values of build type for cmake-gui
#     set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
#             "MinSizeRel" "RelWithDebInfo")
# endif ()

# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# if (0)
#     #设置可执行文件的输出目录
#     SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/out/bin${COMPILEBIT})
#     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/bin${COMPILEBIT}/${CMAKE_BUILD_TYPE})
#     #设置库文件的输出目录
#     SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/out/lib${COMPILEBIT})
#     set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/lib${COMPILEBIT}/${CMAKE_BUILD_TYPE})
# else ()
#     #设置可执行文件的输出目录
#     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/out/bin${COMPILEBIT}/Debug)
#     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/out/bin${COMPILEBIT}/Release)
#     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_SOURCE_DIR}/out/bin${COMPILEBIT}/MinSizeRel)
#     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_SOURCE_DIR}/out/bin${COMPILEBIT}/RelWithDebInfo)
#     #设置库文件的输出目录
#     set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/out/lib${COMPILEBIT}/Debug)
#     set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/out/lib${COMPILEBIT}/Release)
#     set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_SOURCE_DIR}/out/lib${COMPILEBIT}/MinSizeRel)
#     set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_SOURCE_DIR}/out/lib${COMPILEBIT}/RelWithDebInfo)
# endif ()

# add_subdirectory(Test)
# add_subdirectory(AnyDemo)
# add_subdirectory(EnumDemo)
# add_subdirectory(RegexDemo)
# add_subdirectory(AtomicDemo)
# add_subdirectory(RangesDemo)
# add_subdirectory(RandomDemo)
# add_subdirectory(VariantDemo)
# add_subdirectory(OptionalDemo)
# add_subdirectory(ThreadPoolDemo)
# add_subdirectory(SharedMemoryDemo)
# add_subdirectory(PriorityQueueDemo)
# add_subdirectory(SmartPointer)
# add_subdirectory(AttributeDemo)
# add_subdirectory(VariableParameter)
# add_subdirectory(PoolDemo)
# add_subdirectory(ProcessDemo)
# add_subdirectory(shuffle)
# add_subdirectory(piecewise_construct)
# add_subdirectory(Timer)
# add_subdirectory(Coroutine)
# add_subdirectory(polymorphism)
# add_subdirectory(Concepts)
# add_subdirectory(MemFunction)
# add_subdirectory(ToStr)
# add_subdirectory(TokenManager)
# add_subdirectory(IOManager)
# add_subdirectory(BoostDemo)

# if (WIN32)
#     add_subdirectory(IOCP)
#     add_subdirectory(ModuleDemo)
#     add_subdirectory(WinRegDemo)
#     add_subdirectory(CriticalSectionDemo) # 临界区是windows平台的API接口
#     if (MSVC)
#         if (${MSVC_TOOLSET_VERSION} EQUAL 143)
#             # message(${MSVC_VERSION})
#             # message(${MSVC_TOOLSET_VERSION})
#             # message(${CMAKE_CXX_COMPILER_VERSION})
#             add_subdirectory(FormatDemo) # format库目前只有最新的msvc支持ok
#         endif ()
#     endif (MSVC)
# endif (WIN32)


# ------------------------------------------------------ #
include(cmake/SparkEnvConfig.cmake)
include(cmake/SparkMacrosConfig.cmake)
include(cmake/SparkMacrosExtendConfig.cmake)

set(CMAKE_CXX_STANDARD 11)
spark_add_executable_paths(c++11
    # AtomicDemo
    Test
)

# c++17
set(CMAKE_CXX_STANDARD 17)
spark_add_executable_paths(c++17 
    AnyDemo
    EnumDemo
    RegexDemo
    # RangesDemo
    RandomDemo
    VariantDemo
    OptionalDemo
    ThreadPoolDemo
    # SharedMemoryDemo
    PriorityQueueDemo
    SmartPointer
    # AttributeDemo
    VariableParameter
    PoolDemo
    ProcessDemo
    shuffle
    piecewise_construct
# Timer
    # Coroutine
    polymorphism
    # Concepts
    MemFunction
# BoostDemo/BoostAsioEchoServer
    BoostDemo/ChatRoom/server
    # BoostDemo/FirstDemo
)
target_link_libraries(c++17-ThreadPoolDemo pthread)
target_link_libraries(c++17-PoolDemo pthread)

# ---------- boost
# spark_add_executable(BoostAsioEchoServer 
#     BoostDemo/BoostAsioEchoServer/BoostAsioEchoServer.cc)
# spark_add_executable(BoostAsioEchoServerV2 
#     BoostDemo/BoostAsioEchoServer/BoostAsioEchoServerV2.cc)
# ---------- boost

#------------ timer
spark_add_source_paths(TimerSources Timer/src Timer/inc)
spark_add_executable(c++17-Timer ${TimerSources})
target_include_directories(c++17-Timer PUBLIC ${TimerSources_PATHS})
target_link_libraries(c++17-Timer pthread)
#------------ timer

# 系统目前不支持 C++20
set(CMAKE_CXX_STANDARD 20)

# spark_add_executable_paths(c++20
#     Coroutine
#     Concepts
#     ToStr
#     TokenManager
#     IOManager
#     BoostDemo/BoostAsioEchoServer
# )